package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.query.DestinationQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IRegionService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * Created by 甘静斌 on 2020-08-11 19:11
 */
@Controller
@RequestMapping("destination")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;


    //分页操作与吐司查询
    @RequestMapping("/list")
    public Object list(Model model, @ModelAttribute("qo") DestinationQuery qo){

        Page<Destination> page = destinationService.query(qo);
        List<Destination> list = destinationService.findToasts(qo.getParentId());
        model.addAttribute("page",page );
        model.addAttribute("toasts",list );
        return "/destination/list";
    }

    /**
     * 目的地编辑和添加操作
     * @param id
     * @param info
     * @return
     */
    @RequestMapping("/updateInfo")
    @ResponseBody
    public Object updateInfo(String id,String info){

        //根据页面传过来两个数据
        destinationService.updateInfo(id,info);
        return JsonResult.success();

    }


}
